package net

import (
	"fmt"
	"net"
	"time"
)

func Connect(network, addr string) error {
	conn, err := net.DialTimeout(network, addr, 3*time.Second)
	defer func() {
		_ = conn.Close()
	}()
	if err != nil {
		return err
	}

	_, err = conn.Write([]byte("hello"))
	if err != nil {
		return err
	}
	res := make([]byte, 128)
	_, err = conn.Read(res)
	if err != nil {
		return err
	}
	fmt.Println(string(res))
	return nil

}
